import time
from selenium import webdriver

superSite = "http://newbee.dongben.cc:8081"
adminSite = "http://newbee.dongben.cc"
browser = webdriver.Safari()
browser.get(superSite+'/Account/Login')
# browser.find_element_by_id("account").send_keys("wsg")
# browser.find_element_by_id("pwd").send_keys("wsg123456")
browser.find_element_by_id("account").send_keys("cxj")
browser.find_element_by_id("pwd").send_keys("cxj@666")
browser.execute_script("login()")
browser.get(superSite+"/Government")
browser.execute_script("login(2)")
while len(browser.window_handles)<=1:
    time.sleep(1)
target = browser.window_handles[0]
browser.switch_to.window(target)
if browser.title != "政务通登录":
    browser.close()
else:
    target = browser.window_handles[1]
    browser.switch_to.window(target)
    browser.close()
target = browser.window_handles[0]
browser.switch_to.window(target)
while browser.page_source.find("btn_login") == -1:
    time.sleep(1)
time.sleep(1)
browser.execute_script("vueInstance.btnClick()")
time.sleep(1)
browser.get(adminSite+"/Contacts")
time.sleep(1)
browser.execute_script("append();$.ajax({ url: myApi.add,data:{\"deptId\":\"0\",\"name\":\"1\",\"position\":\"\",\"mobile\":\"15036379106\",\"tel\":\"\",\"tel1\":\"\",\"fax\":\"\",\"email\":\"\",\"roomNum\":\"\",\"language\": \"1\",\"Describe\":\"\",\"roles\": \"1\"},success:function(data){console.log(data)}})")
browser.refresh()
